using UnityEngine;
using Voodoo.Sauce.Internal.DebugScreen.CodeStage.AdvancedFPSCounter;

namespace Voodoo.Sauce.Tools.PerformanceDisplay
{
	public static class PerformanceDisplayManager
	{
		private static bool _isEnabled;

		private static AFPSCounter _prefab;

		private const string SHOW_PERFORMANCE_DISPLAY_KEY = "Voodoo_PerformanceDisplayEnabled";

		public static bool IsEnabled
		{
			get
			{
				return _isEnabled;
			}
			set
			{
				SetEnabled(value);
			}
		}

		public static void Initialize(AFPSCounter prefab)
		{
			_prefab = prefab;
			InitializeInternal();
		}

		private static void InitializeInternal()
		{
			if (NintendoPlayerPrefs.GetInt("Voodoo_PerformanceDisplayEnabled", 0) == 1)
			{
				SetEnabled(setEnabled: true);
			}
		}

		private static void SetEnabled(bool setEnabled)
		{
			if (_isEnabled != setEnabled)
			{
				if (setEnabled)
				{
					Object.Instantiate(_prefab);
				}
				else
				{
					AFPSCounter.SelfDestroy();
				}
				_isEnabled = setEnabled;
				NintendoPlayerPrefs.SetInt("Voodoo_PerformanceDisplayEnabled", _isEnabled ? 1 : 0);
			}
		}
	}
}
